<template>
	<div>
		<vxe-modal v-model="dialogVisible" title="请填写电池包相关信息" width="800" height="300" show-zoom resize remember>
			<template #default>
				<vxe-form title-colon ref="xForm" title-align="right" title-width="130" :data="formData2"
					:rules="formRules2" :loading="loading2" @submit="submitEvent2" @reset="resetEvent">
					<vxe-form-gather span="12">
						<vxe-form-item title="类型名称" field="batType" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.batType" placeholder="请输入类型名称"
									clearable @input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
					</vxe-form-gather>
					<vxe-form-gather span="12">
					</vxe-form-gather>
					<vxe-form-item align="center" span="24" :item-render="{}">
						<template #default>
							<vxe-button type="submit" status="primary">提交</vxe-button>
							<vxe-button type="reset">重置</vxe-button>
						</template>
					</vxe-form-item>
				</vxe-form>
			</template>
		</vxe-modal>
	</div>
</template>

<script>
	import {
		sava,
		edit,
	} from './index.js';
	import {
		checkNumber
	} from '@/shop/util/validator.js'
	export default {
		data() {
			return {
				formData2: {
					"batType": '',
				},
				loading2: false,
				formRules2: {
					batType: [{
						required: true,
						message: '请输入类型名称',
						trigger: 'blur'
					}]
					},
					dialogVisible: false,
					loading: false,

			};
		},
		created() {
		},
		methods: {
			handleClose(done) {
				this.resetForm('ruleForm');
				done();
			},
			open(item) {
				console.log(item)
				this.formData2 = {
					...item
				};
				this.dialogVisible = true;
			},
			submitEvent2(e) {
				console.log(e);
				this.loading2 = true
				setTimeout(() => {
					this.loading2 = false
					this.oldsava();
				}, 1000)
			},
			searchEvent() {
				this.msgSuccess('查询事件')
			},
			resetEvent() {
				this.msgSuccess('重置')
			},
			async oldsava() {
				this.loading = true;
				// this.ruleForm.token = localStorage.getItem('goods__token')
				// this.ruleForm.oldname = this.ruleForm.oname;
				let result;
				if(this.formData2.id){
					result = await edit(this.formData2);
				}else{
					result = await sava(this.formData2);
				}
				this.loading = false;
				if (result.code == 1) {
					if (this.formData2.id === undefined) {
						this.msgSuccess("新增成功");
					} else {
						this.msgSuccess("修改成功");
					}

					this.resetForm('formData2');
					this.dialogVisible = false;
					this.$emit('oldlist')
				}

			}
		}
	};
</script>

<style></style>
